package de.breitbeil.jbooking.ui.dialog;

import java.io.File;
import java.io.IOException;
import java.util.Calendar;

import org.springframework.richclient.dialog.FormBackedDialogPage;
import org.springframework.richclient.dialog.TitledPageApplicationDialog;
import org.springframework.richclient.form.Form;
import org.springframework.richclient.settings.SettingsException;
import org.springframework.richclient.settings.SettingsManager;

import de.breitbeil.jbooking.task.FtpCalendarTask;
import de.breitbeil.jbooking.ui.form.FtpCalendarForm;
import de.breitbeil.jbooking.ui.form.FtpCalendarFormObject;
import de.breitbeil.jbooking.ui.form.SaveCalendarFormObject;
import de.breitbeil.jbooking.util.CalendarToImage;

public class FtpCalendarDialog extends TitledPageApplicationDialog {

    public static final String ID = "ftpCalendarDialog"; 

    private Form form;

    public FtpCalendarDialog(SettingsManager settingsManager) throws SettingsException {
        FtpCalendarFormObject formObject = new FtpCalendarFormObject();
        formObject.init(settingsManager.getUserSettings());
        
        form = new FtpCalendarForm(formObject);
        
        setDialogPage(new FormBackedDialogPage(form));
    }

    protected void onInitialized() {
        super.onInitialized();

        setTitle(getMessage(ID + ".title"));
        setTitlePaneTitle(getMessage(ID + ".title"));
        setDescription(getMessage(ID + ".description"));

        setResizable(false);
    }
    
    @Override
    protected boolean onFinish() {
        form.commit();
        FtpCalendarFormObject formObject = (FtpCalendarFormObject) form.getFormObject();
        
        // Save calendar to file
        FtpCalendarTask task = new FtpCalendarTask(formObject);
        task.execute();
        
        return true;
    }
    
}
